var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default, t = require("../../../config/Links"), a = e(require("../../../utils/Tips")), n = e(require("../../../api/api_shareCard")), i = getApp(), r = i.eventBus;

Component({
    properties: {},
    data: {
        shareID: "",
        scene: "",
        sid: "",
        currentIndex: 0,
        autoplay: !0,
        shareCardImageBaseUrl: t.imageBaseUrl.shareCard_static,
        banners: [ {
            icon: t.imageBaseUrl.shareCard_static + "new_users/card1.png"
        }, {
            icon: t.imageBaseUrl.shareCard_static + "new_users/card3.png"
        } ],
        options: {},
        initUrl: ""
    },
    attached: function() {
        var e = this;
        this.setData({
            options: ""
        }), this.getOptions().then(function() {
            return e.getShareInfo();
        }).then(function() {
            return e.initPage();
        });
    },
    detached: function() {
        this.shareCard_newUserOptions && this.shareCard_newUserOptions.off();
    },
    methods: {
        getOptions: function() {
            var e = this;
            return new Promise(function(t, a) {
                e.shareCard_newUserOptions = r.on("shareCard_newUserOptions", function(n) {
                    console.log("attached options", n), e.setData({
                        options: n
                    }), n.sid && n.channel && (i.globalData.aucChannel = n.channel), n.scene || n.sid || a(), 
                    t();
                });
            });
        },
        getShareInfo: function() {
            var e = this;
            return new Promise(function(t, r) {
                wx.showLoading({
                    title: "加载中"
                });
                var s = {
                    scene: e.data.options.scene ? e.data.options.scene : "",
                    sid: e.data.options.sid ? e.data.options.sid : ""
                };
                console.log("获取分享信息传参", s), n.default.getShareInfo(s).then(function(n) {
                    console.log("获取分享信息shareId成功", n), wx.hideLoading();
                    var r = n.code, s = n.result;
                    n.msg;
                    "0" === r && s && s.shareID && s.idType ? (e.setData({
                        shareID: s.shareID,
                        idType: s.idType
                    }), !e.data.options.channel && s && s.channel && (i.globalData.aucChannel = s.channel), 
                    t()) : (a.default.toast("无shareID，邀请人将无法获得奖励"), t());
                }).catch(function(e) {
                    console.log("获取分享信息shareId失败", e), wx.hideLoading(), t(e);
                });
            });
        },
        initPage: function() {
            var e, a = "", n = "&channel=" + i.globalData.aucChannel + "&ADTAG=" + i.globalData.aucChannel;
            return this.data.shareID && this.data.idType && (a = "&ShareID=".concat(this.data.shareID, "&IdType=").concat(this.data.idType)), 
            e = t.baseKCardOrderUrl2 + n + a, this.setData({
                initUrl: e
            }), console.log("initUrl", e), e;
        },
        apply: function() {
            var e = this;
            this.data.shareID && this.data.idType ? e.gotoPage() : wx.showModal({
                content: "没有获取到分享人的信息，请刷新当前页面再下单",
                confirmText: "刷新",
                success: function(t) {
                    var a = this;
                    t.confirm && e.getShareInfo().then(function() {
                        return a.initPage();
                    }).then(function() {
                        e.gotoPage();
                    });
                }
            });
        },
        gotoPage: function() {
            if (!this.data.initUrl) return a.default.toast("未获取到下单路径，请重新进入页面"), !1;
            var e = "";
            switch (i.kta.clickStat("b1a67b87875540b892d478f089b08525"), this.data.currentIndex) {
              case 0:
                e = this.data.initUrl + "&productType=58";
                break;

              case 1:
                e = this.data.initUrl + "&productType=59";
            }
            console.log("gotoUrl", e), this.toWebView(e);
        },
        toWebView: function(e) {
            wx.navigateTo({
                url: "/pages/webview/index"
            }), r.emit("toWebviewPage", {
                url: e
            });
        },
        swiperChange: function(e) {
            console.log(e.detail.current), this.setData({
                currentIndex: e.detail.current
            });
        },
        goto: function(e) {
            switch (e.currentTarget.dataset.index) {
              case "1":
                wx.navigateTo({
                    url: "/pages/shareCard_rules/index?adtag=" + i.globalData.aucChannel
                });
                break;

              case "2":
                this.toWebView(t.newUserPageUrl.mianliu);
                break;

              case "3":
                this.toWebView(t.newUserPageUrl.zifei);
            }
        },
        slideToLeft: function() {
            return 0 === this.data.currentIndex ? (this.setData({
                currentIndex: 1
            }), !0) : (this.setData({
                currentIndex: this.data.currentIndex - 1,
                autoplay: ""
            }), !0);
        },
        slideToRight: function() {
            return 1 === this.data.currentIndex ? (this.setData({
                currentIndex: 0
            }), !0) : (this.setData({
                currentIndex: this.data.currentIndex + 1,
                autoplay: ""
            }), !0);
        }
    }
});